/**
 * 楼栋图册
 * 依赖 jquery
 * 依赖 layer.js 弹窗提示信息
 */
var myuiAlbum_li_template = "<li><img src='__ALBUM_IMG_SRC__'><div style='height: 25px;'>" +
    "<button class='btn btn-xs btn-default' imgid='__ALBUM_IMG_ID__' " +
    "onclick='__ALBUM_DELETE__' style='border: none;color: red;font-weight: normal'>" +
    "<span class='glyphicon glyphicon-remove' aria-hidden='true'>" +
    "</span></button></div></li>";

var myuiAlbum = {
    loadAlbum:function (id) {
        var dom = $("#" + id);
        if( dom.length <= 0 ){
            this.log('error:未找到元素#' + id);
        }

        var url = dom.attr('url');
        var del = dom.attr('del-function');
        this.getAlbumData(url,id,del);
    },
    getAlbumData:function (url,id,del) {
        var that = this;
        $.ajax({
            type:'post',
            url:url,
            success:function (res) {
                var list = JSON.parse(res);
                that.appendAlbum(list,id,del);
            },
            error:function (res) {
                console.log('获取图册数据错误：' + url);
            }
        });
    },
    appendAlbum:function (list,id,del) {
        var dom = $("#" + id);
        var path = dom.attr('path');
        var html = "<ul>";
        for(var i = 0 ; i < list.length ; i++){
            var data = list[i];
            var li = myuiAlbum_li_template.replace('__ALBUM_IMG_SRC__',path + data['FILE_URL']);
            li = li.replace('__ALBUM_IMG_ID__',data['ID']);
            li = li.replace('__ALBUM_DELETE__',del);
            html += li;
        }
        html += "</ul>";
        dom.empty();
        dom.append(html);
    },
    log:function (msg) {
        console.log('myuiAlbum:start**********');
        console.log(msg);
        console.log('myuiAlbum:end**********')
    }


};